home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15056 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: returning an array from function
  5. Date: 3 Apr 1996 12:32:49 GMT
  6. Organization: systems hk
  7. Message-ID: <4jtr5h$h2s@nadine.teleport.com>
  8. References: <4jstd8$kh0@news1.sunbelt.net>
  9. NNTP-Posting-Host: ip-pdx01-07.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. bourne@infoave.net (Rick Huebner) wrote:
  16. >I have looked in several texts and looked through the faq for this question
  17. >and can't find a reference for my answer.  I am trying to return an array, or
  18. >a pointer to the array, from a function.  I have seen several examples of
  19. >returning a pointer, but it doesn't seem to work for me.  My function is going
  20. >to return an array of integers where 1-80 of them will be significant.  The
  21. >calling function will know how many integers are expected and will read them
  22. >off the array....If I can get the pointer back to the array.  A friend of mine
  23. >told me to just make the array a global, but I don't want to do that if I can
  24. >help it.  I would even resort to a recursive function that will pass the
  25. >integers back one at a time if that is possible.  Does anyone have any
  26. >suggestions?  I am open to anything and will go looking if you can tell me
  27. >where(hopefully online somewhere).
  28. >
  29. Rick,
  30. I didn't know whether you meant returning the array as the function value, or
  31. simply as an argument to/from the function.  Assuming the latter:
  32.  
  33. int main ( void )
  34. {
  35.   int  myArray[MAXSIZE];
  36.   int  nElems;
  37.   ...
  38.   ...
  39.   myFunction( myArray,&nElems );
  40.   ...
  41. }
  42.  
  43. void myFunction ( int array[], int *nelems )
  44. {
  45.   ...
  46.   use the 'array'
  47.   ...
  48.   return;
  49. }
  50.  
  51. Yours, Geoff Houck
  52.  
  53.